Skip to content

[client] Fix/health result in bundle#5164

Merged
pappz merged 3 commits intomainfrom
fix/health-result-in-bundle
Jan 23, 2026
Merged

[client] Fix/health result in bundle#5164
pappz merged 3 commits intomainfrom
fix/health-result-in-bundle

Conversation

@pappz
Copy link
Copy Markdown
Collaborator

@pappz pappz commented Jan 23, 2026

Describe your changes

Refresh WireGuard statistics in status queries and debug bundles

WireGuard handshake times and transfer statistics were stale in status
output and debug bundles, relying on cached values updated only during
periodic health probes (every 5+ seconds).

Changes:

  • Add RefreshWireGuardStats() method to status recorder for fast
    WireGuard stats refresh (~1ms)
  • Always refresh WireGuard stats on every status query, independent
    of health probe throttling
  • Update RunHealthProbes() to include WireGuard stats refresh
  • Add callback mechanism to refresh full status (including health probes)
    before debug bundle generation

Result: Status output and debug bundles now contain accurate, real-time
WireGuard handshake times and transfer statistics.

Issue ticket number and link

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • Improvements
    • Health probes now refresh WireGuard statistics for more accurate, up-to-date status reporting.
    • Debug bundles capture current health status at generation time, improving diagnostic accuracy.
    • Background status refreshes are invoked when running probes to keep peer stats current.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 23, 2026

📝 Walkthrough

Walkthrough

Adds an optional RefreshStatus callback into the debug bundle generation flow, invokes it to refresh health/WireGuard stats before embedding status, and consolidates WireGuard stats collection into Status.RefreshWireGuardStats().

Changes

Cohort / File(s) Summary
Debug generator callback
client/internal/debug/debug.go
Adds refreshStatus func() to BundleGenerator and RefreshStatus func() to GeneratorDependencies; calls the callback in addStatus() when present.
WireGuard stats extraction
client/internal/peer/status.go
Adds RefreshWireGuardStats() on Status to fetch WireGuard stats and update peers (handshake time, bytes rx/tx) with proper locking and error handling.
Health probe / engine wiring
client/internal/engine.go, client/server/server.go
RunHealthProbes now uses statusRecorder.RefreshWireGuardStats() instead of direct wgInterface.GetStats; integrates RefreshStatus into bundle deps initialization.
Server debug integration
client/server/debug.go
Defines a local refreshStatus closure that triggers engine.RunHealthProbes(true) when available and passes it into GeneratorDependencies for debug bundle creation.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Server
    participant BundleGen as BundleGenerator
    participant Engine
    participant StatusRec as StatusRecorder

    Client->>Server: Request debug bundle
    Server->>Server: Create refreshStatus callback (calls Engine.RunHealthProbes(true))
    Server->>BundleGen: NewBundleGenerator(deps with RefreshStatus)
    BundleGen->>BundleGen: addStatus()
    alt RefreshStatus provided
        BundleGen->>Server: Invoke RefreshStatus()
        Server->>Engine: RunHealthProbes(true)
        Engine->>StatusRec: RefreshWireGuardStats()
        StatusRec->>StatusRec: Fetch wg stats, update peer metrics
    end
    BundleGen->>Client: Return debug bundle with status
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • mlsmaycon

Poem

🐰 I hopped through code so light and quick,

I nudged the stats, gave probes a kick,
Now bundles bloom with fresher sights,
WireGuard whispers, bytes take flight,
A debug carrot for the midnight tick. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is vague and generic, using non-descriptive terms like 'Fix/health result' that don't clearly convey the specific change being made without additional context. Use a more specific and descriptive title that clearly summarizes the main change, such as 'Refresh WireGuard statistics in status and debug bundles' or 'Fix stale WireGuard stats in status output'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description covers all required sections including a clear summary of changes, identifies it as a bug fix, and confirms documentation is not needed with explanation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pappz pappz marked this pull request as ready for review January 23, 2026 11:56
Comment thread client/server/server.go Outdated
@sonarqubecloud
Copy link
Copy Markdown

@pappz pappz merged commit ee3a67d into main Jan 23, 2026
63 of 67 checks passed
@pappz pappz deleted the fix/health-result-in-bundle branch January 23, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants